// pages/company-detail/company-detail.js
var util = require('../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    companyInfo:{},
    positionInfo:{},
    cityName:"",
    artbanners:{},
    companyvideos:{},
    currentTab: 0, // tab切换 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var companyId = options.id;
    var that=this;
    util.post(app.api.getCompanyByVideo, { companyId: companyId, media_type: 2},function(res){
      that.setData({
        companyvideos:res.data
      })
    })
    //获取文章
    util.post(app.api.getCompanyByVideo, { companyId: companyId, media_type:1},function(res){
      that.setData({
        artbanners:res.data
      })
    });
    util.post(app.api.companyDetail, { id: companyId }, function (res) {
      //获取公司信息
      that.setData({
        companyInfo: res.data
      });
   
    });
    //获取公司职位
    util.post(app.api.getJobdescByCompany, { companyId: companyId},function(res){
        that.setData({
          positionInfo: res.data,
        });
    })
    util.post(app.api.getCompanyByVideo, { companyId: companyId, media_type:2 }, function (res) {
      that.setData({
        companyvideos: res.data
      })
    });
  },
  
  //职位详情
  positionDetailTap: function (event) {
    var id = event.currentTarget.dataset.id; // 当前id
    // 切换页面
    wx.navigateTo({
      url: '../position-detail/position-detail?pid=' + id
    });
  },

  //公司精选文章
  companyDetailTap: function (event) {
    var id = event.currentTarget.dataset.url; // 当前id
    wx.navigateTo({
      url: '../leader/stories/stories?url=' + id
    });
  },
  //跳转微信文章
  artTap: function (event) {
    var id = event.currentTarget.dataset.url; // 当前id
 
    // 切换页面
    wx.navigateTo({
      url: '../leader/stories/stories?url=' + id
    });
  },
  //分享
  onShareAppMessage: function (res) {
    var that = this;
    if (res.from === 'button') {
      // 来自页面内转发按钮
     
    }
    var title = that.data.companyInfo.name;
    return {
      title: title,
      path: 'pages/company-detail/company-detail?id=' + that.data.companyInfo.id,
      data: that.data.companyInfo,
      success: function (res) {
        // 转发成功
         //console.log(res);
      },
      fail: function (res) {
        // console.log(res)
        // 转发失败
      }
    }
  },

  //点击tab切换
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      this.setData({
        currentTab: e.target.dataset.current
      })
    }

  },

})